package com.example.springboot.job;


import com.example.springboot.service.ServiceDoc;
import com.example.springboot.util.SnowFlake;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.slf4j.MDC;
import org.springframework.scheduling.annotation.Scheduled;
import org.springframework.stereotype.Component;

import javax.annotation.Resource;
import java.text.SimpleDateFormat;
import java.util.Date;

@Component
public class DocJob {
   private static final Logger LOG = LoggerFactory.getLogger(DocJob.class);


   @Resource
   private ServiceDoc serviceDoc;

   @Resource
   private SnowFlake snowFlake;
   /**
    * 每5秒更新电子书信息
    */
   @Scheduled(cron = "5/30 * * * * ?")
   public void cron() throws InterruptedException {

       //增加日志流水号
       MDC.put("LOG_ID",String.valueOf(snowFlake.nextId()));
       LOG.info("更新电子书下的文档数据开始");
       //获取当前时间戳
       Long start = System.currentTimeMillis();
       serviceDoc.updateEbookInfo();
       LOG.info("更新电子书下的文档数据结束，耗时：{}毫秒",System.currentTimeMillis() - start);
   }

}

